package com.itheima.controller;
import com.itheima.MyDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController  //@Controller 和 @ResponseBody的结合体  并且支持RESTful风格的URL
@RequestMapping("/books")
public class BookController {
    @Value("${country}")
    private String country1;

    @Value("${user1.name}")
    private String name1;

    @Value("${likes[1]}") //数组索引从0开始
    private String music;

    @Value("${users[0].age}")
    private String age;

    @Value("${server.port}")
    private String port;

    @Value("${tempDir}")
    private String dir;

    //使用自动装配将所有的数据封装到一个对象Environment
    @Autowired
    private Environment env;

    @Autowired
    private MyDataSource myDataSource;

    @GetMapping
    public String getById(){
        System.out.println("country1==>"+country1);
        System.out.println("name1==>"+name1);
        System.out.println("music==>"+music);
        System.out.println("age==>"+age);
        System.out.println("port==>"+port);
        System.out.println("dir==>"+dir);
        System.out.println("=======================");
        System.out.println(env.getProperty("server.port"));
        System.out.println(env.getProperty("users[0].age"));
        System.out.println(myDataSource.getUsername());
        System.out.println("springboot is running...03");
        return "springboot03 is running";
    }
}
